-- SPDX-License-Identifier: GPL-3.0-or-later

local extension = Package:new("old2")
extension.extensionName = "vupslash"
-- extension.extensionName = "VslTest"
-- extension.game_modes_whitelist = { 'nos_heg_mode', 'new_heg_mode' }
-- dofile "packages/vupslash/game_rule.lua"

local VslUtil = require "packages/vupslash/util"
-- local VslUtil = require "packages/VslTest/util"

--------------------------------------------------
--测试技能：超级英姿
--------------------------------------------------

local super_yingzi = fk.CreateTriggerSkill{
    name = "superyingzi",
    anim_type = "drawcard",
    events = {fk.DrawNCards},
    on_use = function(self, event, target, player, data)
        data.n = data.n + 20
    end,
}

--------------------------------------------------
--测试技能：摸指定牌
--------------------------------------------------

local v_cheat = fk.CreateActiveSkill{
    name = "v_cheat",
    anim_type = "drawcard",
    can_use = function(self, player)
        return true
    end,
    on_use = function(self, room, effect)
        local from = room:getPlayerById(effect.from)
        local cardTypeName = room:askForChoice(from, { 'basic', 'trick', 'equip' }, "cheat")
        local cardType = Card.TypeBasic
        if cardTypeName == 'trick' then
            cardType = Card.TypeTrick
        elseif cardTypeName == 'equip' then
            cardType = Card.TypeEquip
        end

        local allCardIds = Fk:getAllCardIds()
        local allCardMapper = {}
        local allCardNames = {}
        for _, id in ipairs(allCardIds) do
            local card = Fk:getCardById(id)
            if card.type == cardType then
                if allCardMapper[card.name] == nil then
                    table.insert(allCardNames, card.name)
                end

                allCardMapper[card.name] = allCardMapper[card.name] or {}
                table.insert(allCardMapper[card.name], id)
            end
        end

        if #allCardNames == 0 then
            return
        end

        local cardName = room:askForChoice(from, allCardNames, "cheat")
        local toGain = nil
        if #allCardMapper[cardName] > 0 then
            toGain = allCardMapper[cardName][math.random(1, #allCardMapper[cardName])]
        end

        from:addToPile(self.name, toGain, true, self.name)
        room:obtainCard(effect.from, toGain, true, fk.ReasonPrey)
    end
}
  
--------------------------------------------------
--测试技能：流失体力
--------------------------------------------------

local v_lose = fk.CreateActiveSkill{
    name = "v_lose",
    anim_type = "offensive",
    can_use = function(self, player)
        return true
    end,
    target_num = 1,
    -- card_num = 1,
    card_filter = function(self, to_select, selected, selected_targets)
        return false
        -- if #selected == 1 then return false end
        -- return Fk:currentRoom():getCardArea(to_select) ~= Player.Equip
    end,
    target_filter = function(self, to_select, selected)
        -- local target = Fk:currentRoom():getPlayerById(to_select)
        return #selected == 0
    end,
    on_use = function(self, room, effect)
        local player = room:getPlayerById(effect.from)
        local target = room:getPlayerById(effect.tos[1])
        room:loseHp(target, 1, self.name)
    end,
}

-- 加载本包的翻译包(load translations of this package)，这一步在本文档的最后进行。
dofile "packages/vupslash/i18n/init.lua"
-- dofile "packages/VslTest/i18n/init.lua"
  
-- return { extension } 

return extension